//逃离图困难增强模组 - by k1 2018.2.16 - 2021.12.25
//倒下会随机掉装备
//捡装备有时间限制
//倒下没人救过15分钟后会被踢出到大厅
//一个地方待太久也被踢出
//可以禁用坦克，装甲车，迫击炮!

if (Escape_MOD1 || {Escape_MOD2} || {Escape_MOD3} || {Escape_MOD4} || {Escape_MOD5}) then {
Escape_MOD_xx = {
Escape_delete_Gear = true;
Escape_open_Gear = true;
Escape_Gear_num = 0;
Escape_isUnconscious_time = 0;
Escape_dist_check = time + 10;
Escape_Static_time = 0;
Escape_start_pos = [0,0];
_pos1 = [0,0,0];

Escape_delete_items = {
	_return = "";
	_items = uniformItems player + VestItems player + backpackItems player;
	_count = count _items;
	if (_count > 0) then {
		_i = 0;
		_c = [1,10] call BIS_fnc_randomInt;//
		{if(random 100 < 40 && {_i < _c})then{player removeItem _x; _i = _i + 1;}} forEach _items;
		_items = uniformItems player + VestItems player + backpackItems player;
		if(_count != count _items)then{_return = "丢失了一些物品(制服背心背包中的)"};
	};
	_return
};

waitUntil {
	if (alive player && {player getVariable ['FAR_isUnconscious',0] == 1}) then [{
	
		if (Escape_delete_Gear) then {
			Escape_delete_Gear = false;
		if (Escape_MOD1) then {
			//_primary = primaryWeapon player;
			_launcher = secondaryWeapon player;
			_handgun = handGunWeapon player;
			//_vest = vest player;
			//_backpack = backpack player;
			_optics = (primaryWeaponItems player) select 2;
			
			_txt = switch (floor(random 14)) do {
				case 0: {""};
				case 1: { if(_optics != "")then[{player removePrimaryWeaponItem _optics; "丢失装备: 瞄镜"},{""}] };
				case 2: {call Escape_delete_items};
				case 3: {""};
				case 4: {call Escape_delete_items; /*if(_primary != "")then[{player removeWeapon _primary; if(_handgun == "")then[{{player addMagazine _x} forEach ["16Rnd_9x21_Mag","16Rnd_9x21_Mag","16Rnd_9x21_Mag"]; player addWeapon "hgun_P07_F"; "主武器丢失，获得手枪一把"},{"丢失装备: 主武器"}]},{""}]*/ };
				case 5: {""};
				case 6: { if(_launcher != "")then[{player removeWeapon _launcher; "丢失装备: 副武器"},{""}] };
				case 7: {call Escape_delete_items};
				case 8: {call Escape_delete_items; /*if(_backpack != "")then[{removeBackpack player; "丢失装备: 背包"},{""}]*/ };
				case 9: {""};
				case 10: {call Escape_delete_items; /*if(_vest != "")then[{removeVest player; "丢失装备: 背心"},{""}]*/ };
				case 11: {call Escape_delete_items};
				case 12: { if(_optics != "")then[{player removePrimaryWeaponItem _optics; "丢失装备: 瞄镜"},{""}] };
				default {""};
			};
			if (_txt != "") then {
				sleep 2;
				[format["<t color='#FF0000' size = '.8'>%1</t>", _txt],-1,0,8,0,0,7374] spawn BIS_fnc_dynamicText;
				format["%1 %2", name player, _txt] remoteExec ["systemChat", 0, false];
			};
		};};
	
		if (Escape_MOD2 && {!isServer} && {player != Player_Server} && {isNil "Escape_enemySW_side"}) then {
			if(Escape_isUnconscious_time == 0)then{Escape_isUnconscious_time = time + 900};
			if (time > Escape_isUnconscious_time && {{_x distance player > 800 || {_x getVariable ["AT_Revive_isUnconscious",false]} || {_x getVariable ['FAR_isUnconscious',0] == 1}} count (call A3E_fnc_GetPlayers - [Player_Server] - Escape_Players_enemy) == count (call A3E_fnc_GetPlayers - [Player_Server] - Escape_Players_enemy)}) then {
				Escape_isUnconscious_time = 0;
				["<t size = '.8'>你已经倒下很长时间了，请重进！</t>",-1,0,999,0,0,7374] spawn BIS_fnc_dynamicText;
				sleep 2;
				["end298",false,false,false,false] call BIS_fnc_endMission;
			};
		};
	},{
		if (!Escape_delete_Gear) then {
			Escape_delete_Gear = true;
			Escape_isUnconscious_time = 0;
		};
	}];
	
	if (Escape_MOD3 && {!isServer} && {isNil "Escape_enemySW_side"}) then {
		if (player == Player_Server) exitWith {if(Escape_Static_time > 0)then{Escape_Static_time = 0}};
		if (time > Escape_dist_check) then {
			Escape_dist_check = time + 10;
			_pos1 = getPosASL player;
		};
		_dis = if(surfaceIsWater getPosASL player || {player getHit "legs" >= .5})then [{5},{20}];
		if ((getPosASL player distance _pos1) < _dis && {player getVariable ['FAR_isUnconscious',0] == 0} && {!(player getVariable ["AT_Revive_isUnconscious",false])} && {alive player}) then [{
			if(Escape_Static_time == 0)then{Escape_Static_time = time + 480};
			_Static = round (Escape_Static_time - time);
			if(_Static <= 60 && {_Static > 30})then{[format["<t color='#fff000' size = '.8'>你已经在这里待太久了，再不移动就被踢出！ %1秒</t>", _Static],-1,0,3,0,0,7374] spawn BIS_fnc_dynamicText};
			if(_Static <= 30 && {_Static >= 0})then{[format["<t color='#FF0000' size = '.8'>你至少要走出%1米远！ %2秒</t>", _dis, _Static],-1,0,3,0,0,7374] spawn BIS_fnc_dynamicText};
			if (time > Escape_Static_time) then {
				Escape_Static_time = 0;
				["<t color='#FF0000' size = '.8'>你窝在这里太久被踢出！</t>",-1,0,999,0,0,7374] spawn BIS_fnc_dynamicText;
				sleep 2;
				["end298",false,false,false,false] call BIS_fnc_endMission;
			};
		},{if(Escape_Static_time > 0)then{Escape_Static_time = 0}}];
	};
	
if (Escape_MOD4) then {
	_veh = vehicle player;
	if (_veh != player && {_veh isKindOf "Tank" || {_veh isKindOf "StaticMortar"}}) then {
		["<t color='#fff000' size = '.8'>禁用坦克，装甲车，迫击炮</t>",-1,-1,4,2,0,789] spawn BIS_fnc_dynamicText;
		moveOut player;
	};
};
	
	_weight = loadAbs player;
	sleep .2;
	
if (Escape_MOD5 && {isNil "Escape_enemySW_side"}) then {
	_weight spawn {
		if ({_x distance2D player < 300} count (player getVariable ["Escape_pos_tmp", [[0,0]]]) > 0) exitWith {};
		if (Escape_Gear_num > 0 && {Escape_start_pos distance2D player > 20}) then {Escape_Gear_num = 0};
		if (!isNull(FindDisplay 602) && {Escape_open_Gear} && {loadAbs player > _this} && {{(_x select 0) distance2D player < 20} count (player getVariable ["Escape_pos_time", []]) == 0} && {vehicle player == player}) then {
			Escape_open_Gear = false;
			waitUntil {isNull(FindDisplay 602)};
			Escape_open_Gear = true;
			Escape_start_pos = getPosASL player;
			Escape_Gear_num = Escape_Gear_num + 1;
			hint format["在此处舔包 %1次", Escape_Gear_num];
			if (Escape_Gear_num > 2) then {
				_time = time + 120;
				Escape_Gear_num = 0;
				_pos = Escape_start_pos;
				_x = -1.1;
				_pos_tmp = player getVariable ["Escape_pos_tmp", []];
				_pos_tmp pushback _pos;
				player setVariable ["Escape_pos_tmp", _pos_tmp];
				waitUntil {
					if (_pos distance2D player < 300) then {
						_time2 = round (_time - time);
						_rate = round (60 / diag_fps);
						if (_time2 >= 2.3 && {_x < -0.78}) then {_x = _x + (.005 * _rate)};
						if (_time2 < 2.3 && {_x > -1.1}) then {_x = _x - (.005 * _rate)};
						[format["<t color='#FF0000' size = '.6'>本区域即将禁用装备栏，剩余%1秒</t>", _time2],_x,.1,3,0,0,7364] spawn BIS_fnc_dynamicText;
					};
					(time > _time)
				};
				_pos_time = player getVariable ["Escape_pos_time", []];
				_pos_time pushback [_pos, time + 600];
				player setVariable ["Escape_pos_time", _pos_time];
				_pos_tmp = player getVariable "Escape_pos_tmp";
				_pos_tmp = _pos_tmp - [_pos];
				player setVariable ["Escape_pos_tmp", _pos_tmp];
				if (_pos distance2D player < 300) then {["<t color='#FF0000' size = '.8'>锁定装备栏，600秒后解锁</t>",-1,0,5,0,0,7374] spawn BIS_fnc_dynamicText};
			};
		};
	};
	_time2 = 0;
	_dist = 300;
	_pos_time = player getVariable ["Escape_pos_time", []];
	{
		_time = _x select 1;
		if (time > _time) then {
			_pos_time = _pos_time - [_x];
			player setVariable ["Escape_pos_time", _pos_time];
		};
	} forEach _pos_time;
	_count = {
		_x params ["_pos", "_time"];
		if (_pos distance2D player < _dist) then {
			_time2 = _time - time;
			_dist = _pos distance2D player;
		};
		(!isNull(FindDisplay 602) && {_pos distance2D player < 300} && {vehicle player == player})
	} count _pos_time;
	if (_count > 0) then {
		closedialog 0;
		[format["<t color='#FF0000' size = '.8'>在这里暂时不能打开装备栏<br/>你在限制区%1米，解锁还剩%2秒</t>", floor _dist, round _time2],-1,0,5,0,0,7374] spawn BIS_fnc_dynamicText;
	};
};
	false
}};

call Escape_MOD_xx;
};


